package 卖票;

/**
 * @author Administrator
 * @ClassName TicketTest
 * @TIME 星期三 2020/12/30
 */
public class TicketTest {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        Thread t1 = new Thread(ticket);
        Thread t2 = new Thread(ticket);
        Thread t3 = new Thread(ticket);
        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");

        t1.start();
        t2.start();
        t3.start();
    }
}

class Ticket implements Runnable {
    int ticket = 100;
    @Override
    public void run() {
        for (int i = 0; i < ticket; i++) {
                System.out.println(Thread.currentThread().getName() + "买了第" + ticket + "张票");
                ticket--;
        }
        System.out.println("还剩" + ticket);
    }
}